/**
 * @Title: ForumServiceImpl.java
 * @Package com.zll.ccp.service.forum.impl
 * @author zhanglinlu
 * @date 2019年5月30日 下午3:25:01
 */
package com.zll.ccp.service.forum.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zll.ccp.mapper.IMainPostsMapper;
import com.zll.ccp.mapper.IMinorPostsMapper;
import com.zll.ccp.mapper.IThemeMapper;
import com.zll.ccp.model.forum.MainPosts;
import com.zll.ccp.model.forum.MinorPosts;
import com.zll.ccp.model.forum.Theme;
import com.zll.ccp.service.forum.IForumService;

/**
 * @ClassName: ForumServiceImpl
 * @Description: 论坛service实现类
 * @author zhanglinlu
 * @date 2019年5月30日 下午3:25:01
 * 
 */
@Service
@Transactional
public class ForumServiceImpl implements IForumService {
    @Autowired
    private IThemeMapper themeMapper;

    @Autowired
    private IMainPostsMapper mainPostsMapper;

    @Autowired
    private IMinorPostsMapper minorPostsMapper;

    /* (non-Javadoc)
     * @param theme
     * @see com.zll.ccp.service.forum.IForumService#addTheme(com.zll.ccp.model.forum.Theme)
     */
    @Override
    public void addTheme(Theme theme) {
        themeMapper.addTheme(theme);
    }

    /* (non-Javadoc)
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getThemeList()
     */
    @Override
    public List<Map<String, String>> getThemeList(String name, String ct) {
        return themeMapper.getThemeList(name, ct);
    }

    /* (non-Javadoc)
     * @param id
     * @see com.zll.ccp.service.forum.IForumService#deleteThemeById(java.lang.String)
     */
    @Override
    public void deleteThemeById(String id) {
        themeMapper.deleteThemeById(id);
    }

    /* (non-Javadoc)
     * @param mainPosts
     * @see com.zll.ccp.service.forum.IForumService#addMainPosts(com.zll.ccp.model.forum.MainPosts)
     */
    @Override
    public void addMainPosts(MainPosts mainPosts) {
        mainPostsMapper.addMainPosts(mainPosts);
    }

    /* (non-Javadoc)
     * @param id
     * @see com.zll.ccp.service.forum.IForumService#deleteMainPostsById(java.lang.String)
     */
    @Override
    public void deleteMainPostsById(String id) {
        mainPostsMapper.deleteMainPostsById(id);
    }

    /* (non-Javadoc)
     * @param title
     * @param ct
     * @param themeid
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getMainPostesByFilter(java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public List<Map<String, String>> getMainPostesByFilter(String title, String ct, String themeid) {
        return mainPostsMapper.getMainPostesByFilter(title, ct, themeid);
    }

    /* (non-Javadoc)
     * @param id
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getMainPostsById(java.lang.String)
     */
    @Override
    public Map<String, String> getMainPostsById(String id) {
        return mainPostsMapper.getMainPostsById(id);
    }

    /* (non-Javadoc)
     * @param id
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getMinorPostesByMainId(java.lang.String)
     */
    @Override
    public List<Map<String, String>> getMinorPostesByMainId(String id) {
        return minorPostsMapper.getMinorPostesByMainId(id);
    }

    /* (non-Javadoc)
     * @param minorPosts
     * @return
     * @see com.zll.ccp.service.forum.IForumService#addMinorPosts(com.zll.ccp.model.forum.MinorPosts)
     */
    @Override
    public void addMinorPosts(MinorPosts minorPosts) {
        int a = minorPostsMapper.addMinorPosts(minorPosts);
        System.out.println(a);
    }

    /* (non-Javadoc)
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getHotTheme()
     */
    @Override
    public List<Map<String, String>> getHotTheme() {
        List<Map<String, String>> hotThemes = themeMapper.getHotTheme();
        if (CollectionUtils.isEmpty(hotThemes)) {
            hotThemes = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("name", "----");
                item.put("count", "----");
                hotThemes.add(item);
            }
        } else if (hotThemes.size() < 5) {
            int rest = 5 - hotThemes.size();
            for (int i = 0; i < rest; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("name", "----");
                item.put("count", "----");
                hotThemes.add(item);
            }
        }
        return hotThemes;
    }

    /* (non-Javadoc)
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getNewTheme()
     */
    @Override
    public List<Map<String, String>> getNewTheme() {
        List<Map<String, String>> newThemes = themeMapper.getNewTheme();
        if (CollectionUtils.isEmpty(newThemes)) {
            newThemes = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("name", "----");
                item.put("createtime", "----");
                newThemes.add(item);
            }
        } else if (newThemes.size() < 5) {
            int rest = 5 - newThemes.size();
            for (int i = 0; i < rest; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("name", "----");
                item.put("createtime", "----");
                newThemes.add(item);
            }
        }
        return newThemes;
    }

    /* (non-Javadoc)
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getHotMain()
     */
    @Override
    public List<Map<String, String>> getHotMain() {
        List<Map<String, String>> hotMains = mainPostsMapper.getHotMain();
        if (CollectionUtils.isEmpty(hotMains)) {
            hotMains = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("title", "----");
                item.put("count", "----");
                hotMains.add(item);
            }
        } else if (hotMains.size() < 5) {
            int rest = 5 - hotMains.size();
            for (int i = 0; i < rest; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("title", "----");
                item.put("count", "----");
                hotMains.add(item);
            }
        }
        return hotMains;
    }

    /* (non-Javadoc)
     * @return
     * @see com.zll.ccp.service.forum.IForumService#getNewMain()
     */
    @Override
    public List<Map<String, String>> getNewMain() {
        List<Map<String, String>> newMains = mainPostsMapper.getNewMain();
        if (CollectionUtils.isEmpty(newMains)) {
            newMains = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("title", "----");
                item.put("createtime", "----");
                newMains.add(item);
            }
        } else if (newMains.size() < 5) {
            int rest = 5 - newMains.size();
            for (int i = 0; i < rest; i++) {
                Map<String, String> item = new HashMap<>();
                item.put("title", "----");
                item.put("createtime", "----");
                newMains.add(item);
            }
        }
        return newMains;
    }

}
